<?php
namespace app\common\model;

class ProductViewLog extends Base
{
    protected $table = 'product_view_logs';

    public function getCreateTimeLabelAttr($value, $data)
    {
       if (!isset($data['create_time']) || empty($data['create_time'])) {
           return '';
       }
       
       return date("Y-m-d H:i:s", $data['create_time']);
    }

    public function getIpLabelAttr($value, $data)
    {
        if (!isset($data['ip']) || empty($data['ip'])) {
            return '';
        }

        return long2ip(intval($data['ip']));

    }

    public function getProductIdLabelAttr($value, $data)
    {
        $product = Product::get(array('id' => $data['product_id']));

        if (empty($product)) {
            return '';
        }

        return $product['title'];
    }

    public function getMemberIdLabelAttr($value, $data)
    {
       $member = Member::get(array('id' => $data['member_id']));
       if (empty($member)) {
          return '';
       }

       $phone = $member['phone'];

       $phone = substr($phone, 0, 3) . str_repeat('*', strlen($phone) -7) . substr($phone, -4);

       return $phone;
    }

    public function getMemberFromAttr($value, $data)
    {
        $member = Member::get(array('id' => $data['member_id']));
        if (!empty($member)) {
            $channel = Channel::get(array('id' => $member->channel_id));
            if (!empty($channel)) {
               return $channel['name'];
            }
        }

        return '';
    }
    
    
    
    
}

